<%--
  document: search-result.jsp
  
  description:
    Display search results.
 --%>

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%-- Importations --%>
<%@page import="javax.faces.context.*" %>
<%@page import="javax.el.*" %>
<%@page import="com.reimscopie.*" %>
<%@page import="com.reimscopie.controlers.*" %>
<%@page import="javax.naming.*" %>
<%@page import="javax.transaction.*" %>
<%@page import="com.reimscopie.beans.interfaces.* "%>

<%-- Tag libs --%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="core"%> 
<%@taglib uri="http://java.sun.com/jsf/html" prefix="html"%> 

<%-- Controlers --%>
<%@ include file="jspf/controlers.jspf" %>

<%-- i18n --%>
<%@include file="jspf/i18n/i18n.jspf" %>

<%
    SearchControler controler = (SearchControler)resolver.getValue(elContext,null,"SearchControler") ;
    Product[] products = controler.getResult() ;
    %>
    
<%
    Context context = new InitialContext() ;
    String name ="com.reimscopie.beans.session.ReimsCopieUserBean_" +
    ReimsCopieUserLocal.class.getName()+"@Local" ;    
    ReimsCopieUserLocal bean = (ReimsCopieUserLocal)context.lookup(name) ;   
    
    String transactionName = "javax.transaction.UserTransaction" ;
    UserTransaction transaction =
            (UserTransaction)context.lookup(transactionName);
    transaction.begin() ;
%>
    

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">

<html>
	<head>
    <%@ include file = "jspf/header.jspf" %>
	</head>
  
  <body>

<core:view>
  
  <div id="page">
  
  <%@include file = "jspf/top.jspf" %>
  
  <div id="middle">
    <div id="menu">
      <div id="search">
        <%@ include file = "jspf/search.jspf" %>
      </div>
      <div id="menu_task">
        <%@ include file = "jspf/home/menu.jspf" %>
      </div>
    </div>
    <div id="contents">
      <div id="onglet">
        <%! String activeTab = "null"; %>
        <%@ include file = "jspf/onglet.jspf" %>
      </div>
      <div id="tree">
        >> <%= i18nBundle.getString("search") %>
      </div>
      <div id="in">
<%
    String target = "" ;
    out.print("<div class=\"hautgroscadre\">") ;
    out.print("<br>") ;
    
    if (products.length==0)
      out.print(i18nBundle.getString("noresult")+" \""+controler.getExpr()+"\"");
    else {
        out.print(i18nBundle.getString("searchresult")+" \" "+controler.getExpr()+" \" "+i18nBundle.getString("is")+"");
        out.print("</div>") ;
        out.print("<div class=\"milieugroscadre\">") ;
        out.print("<br>") ;
        
        for (Product product : products) {
           
           if(product instanceof SimpleProduct)
             target = "sale.jsf" ;
           
           else if(product instanceof SpecialProduct)
             target = "support.jsf" ;
           
         out.print("<a href=\""+target+"?navigation="+product.getId()+"\">");
         out.print("<b>"+product.getName()+ "</b><br></a>") ;
         out.print("<br>") ;
       }
    }
    out.print("</div>") ;
    out.print("<div class=\"basgroscadre\">") ;
    out.print("</div>") ;
%>
        </div>
    </div>
  </div>
  
  <div id="page_end">
    <%@ include file = "jspf/page-end.jspf" %>
  </div>
  
</core:view>

<%@ include file = "jspf/footer.jspf" %>

<%
    transaction.commit();    
%>
  
